﻿using System.ComponentModel.Composition;
using System.IO;
using System.Xml.Serialization;

namespace Templates.Models
{
    [Export(typeof(Serializer))]
    public class Serializer
    {
        private readonly XmlSerializer _serializer = new XmlSerializer(typeof(Template));

        public Template Open(string path)
        {
            using (var stream = File.OpenRead(path))
            {
                return _serializer.Deserialize(stream) as Template;
            }
        }

        public void Save(string path, Template template)
        {
            using (var stream = File.Create(path))
            {
                _serializer.Serialize(stream, template);
            }
        }
    }
}
